	//
	//  DailyStatistics.swift
	//  hello
	//
	//  Created by 赵康 on 2024/12/21.
	//
import Fluent
import Vapor

final class DailyStatistics: Model, Content, @unchecked Sendable {
	static var schema: String { SchemaEnum.dailyStatistics.rawValue }
	@ID(key: .id)
	var id: UUID?
	
	@Field(key: FieldKeys.date)
	var date: Date // 统计日期
	
	@Field(key: FieldKeys.totalDuration)
	var totalDuration: Double // 总收听时长
	
	@Parent(key: FieldKeys.user)
	var user: User // 用户关联
	
	@OptionalField(key: FieldKeys.tagID)
	var tagID: UUID? // 标签关联, 为空表示所有类型, 不为空表示某个类型
	
	@Timestamp(key: FieldKeys.createdAt, on: .create)
	var createdAt: Date?
	
	@Timestamp(key: FieldKeys.updatedAt, on: .update)
	var updatedAt: Date?
	
	init() { }
	
	init(
		id: UUID? = nil,
		date: Date,
		totalDuration: Double,
		userID: User.IDValue,
		tagID: UUID? = nil
	) {
		self.id = id
		self.date = date
		self.totalDuration = totalDuration
		self.$user.id = userID
		self.tagID = tagID
	}
}
